<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>SPHinXsys: SPHINXsys/src/shared/common/ownership.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">SPHinXsys
   &#160;<span id="projectnumber">alpha version</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_3dc1dabd28ba78e072d14d3fcfc90454.html">SPHINXsys</a></li><li class="navelem"><a class="el" href="dir_48ea983704c43b6d88c1fa3f4d09e369.html">src</a></li><li class="navelem"><a class="el" href="dir_0a0d9ef1793521534f0094f317758287.html">shared</a></li><li class="navelem"><a class="el" href="dir_4b0a73e0e85ea3fdcd68e2975aa1af86.html">common</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#namespaces">Namespaces</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">ownership.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Here, the classes related to the ownership of objects are defined by implementing Resource Acquisition Is Initialization (RAII). The basic idea in SPHinXsys to use defined ownership. Unique pointers are used as much as possible and shared pointer only used when a default smart pointer is generated as argument in the constructors. In this case, for objects with statically defined lifetime, references will be used. For those with dynamical lifetime, we will use smart-pointer keepers to handel. Basically, new a raw pointer is forbidden through out the code except for raw matrixes, such as the cell linked list mesh, that will be deleted in destructor, especially, when new features are introduced. Generally, the classes here are private member and the smart pointer is used only when the memory is allocated. After that, we take reference or raw pointer out and use them as observer.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &quot;base_data_type.h&quot;</code><br />
<code>#include &lt;typeinfo&gt;</code><br />
</div>
<p><a href="ownership_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_s_p_h_1_1_unique_ptr_keeper.html">SPH::UniquePtrKeeper&lt; BaseType &gt;</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">A wrapper to provide an ownership for a new derived object which previous often generated by new a raw pointer.  <a href="class_s_p_h_1_1_unique_ptr_keeper.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_s_p_h_1_1_unique_ptr_keepers.html">SPH::UniquePtrKeepers&lt; BaseType &gt;</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">A wrapper to provide an ownership for a vector of base class pointers which point to derived objects. It should be a private member.  <a href="class_s_p_h_1_1_unique_ptr_keepers.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_s_p_h_1_1_shared_ptr_keeper.html">SPH::SharedPtrKeeper&lt; BaseType &gt;</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">A wrapper to provide an shared ownership for a new derived object which previous often generated by new a raw pointer.  <a href="class_s_p_h_1_1_shared_ptr_keeper.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:namespace_s_p_h"><td class="memItemLeft" align="right" valign="top"> &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_s_p_h.html">SPH</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:a3c97d0352cefc0224fcdfd096784b416"><td class="memTemplParams" colspan="2"><a id="a3c97d0352cefc0224fcdfd096784b416"></a>
template&lt;class T &gt; </td></tr>
<tr class="memitem:a3c97d0352cefc0224fcdfd096784b416"><td class="memTemplItemLeft" align="right" valign="top">using&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::UniquePtr</b> = std::unique_ptr&lt; T &gt;</td></tr>
<tr class="separator:a3c97d0352cefc0224fcdfd096784b416"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a23cee897c6c85d6879f1930223627dc0"><td class="memTemplParams" colspan="2"><a id="a23cee897c6c85d6879f1930223627dc0"></a>
template&lt;class T &gt; </td></tr>
<tr class="memitem:a23cee897c6c85d6879f1930223627dc0"><td class="memTemplItemLeft" align="right" valign="top">using&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::SharedPtr</b> = std::shared_ptr&lt; T &gt;</td></tr>
<tr class="separator:a23cee897c6c85d6879f1930223627dc0"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ae60ed50a46879bbff92c3175ed0d6754"><td class="memTemplParams" colspan="2"><a id="ae60ed50a46879bbff92c3175ed0d6754"></a>
template&lt;class CastingType , class OwnerType , class CastedType &gt; </td></tr>
<tr class="memitem:ae60ed50a46879bbff92c3175ed0d6754"><td class="memTemplItemLeft" align="right" valign="top">CastingType *&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::DynamicCast</b> (OwnerType *owner, CastedType *casted)</td></tr>
<tr class="separator:ae60ed50a46879bbff92c3175ed0d6754"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a32a89e83021bf3054cdd64d9705e0c28"><td class="memTemplParams" colspan="2"><a id="a32a89e83021bf3054cdd64d9705e0c28"></a>
template&lt;class CastingType , class OwnerType , class CastedType &gt; </td></tr>
<tr class="memitem:a32a89e83021bf3054cdd64d9705e0c28"><td class="memTemplItemLeft" align="right" valign="top">CastingType &amp;&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::DynamicCast</b> (OwnerType *owner, CastedType &amp;casted)</td></tr>
<tr class="separator:a32a89e83021bf3054cdd64d9705e0c28"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:adc3aa383cc1fa702fd4e96d945af4690"><td class="memTemplParams" colspan="2"><a id="adc3aa383cc1fa702fd4e96d945af4690"></a>
template&lt;class T , typename... ConstructorArgs&gt; </td></tr>
<tr class="memitem:adc3aa383cc1fa702fd4e96d945af4690"><td class="memTemplItemLeft" align="right" valign="top">UniquePtr&lt; T &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::makeUnique</b> (ConstructorArgs &amp;&amp;...args)</td></tr>
<tr class="separator:adc3aa383cc1fa702fd4e96d945af4690"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6a31a8390ea00600b1dddd7d90143ae9"><td class="memTemplParams" colspan="2"><a id="a6a31a8390ea00600b1dddd7d90143ae9"></a>
template&lt;class T , typename... ConstructorArgs&gt; </td></tr>
<tr class="memitem:a6a31a8390ea00600b1dddd7d90143ae9"><td class="memTemplItemLeft" align="right" valign="top">SharedPtr&lt; T &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><b>SPH::makeShared</b> (ConstructorArgs &amp;&amp;...args)</td></tr>
<tr class="separator:a6a31a8390ea00600b1dddd7d90143ae9"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Here, the classes related to the ownership of objects are defined by implementing Resource Acquisition Is Initialization (RAII). The basic idea in SPHinXsys to use defined ownership. Unique pointers are used as much as possible and shared pointer only used when a default smart pointer is generated as argument in the constructors. In this case, for objects with statically defined lifetime, references will be used. For those with dynamical lifetime, we will use smart-pointer keepers to handel. Basically, new a raw pointer is forbidden through out the code except for raw matrixes, such as the cell linked list mesh, that will be deleted in destructor, especially, when new features are introduced. Generally, the classes here are private member and the smart pointer is used only when the memory is allocated. After that, we take reference or raw pointer out and use them as observer. </p>
<dl class="section author"><dt>Author</dt><dd>Xiangyu Hu </dd></dl>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>
